package com.zyf.chapter01.principle.SOLID.LSP;

import com.zyf.chapter01.principle.SOLID.LSP.utils.*;

/**
 * 违反里式替换原则
 * 支持安全认证的网络传输类
 * @author yifeng
 */
public class ViolateSecurityTransporter extends Transporter{
    private String appId;
    private String appToken;

    public ViolateSecurityTransporter(HttpClient httpClient, String appId, String appToken) {
        super(httpClient);
        this.appId = appId;
        this.appToken = appToken;
    }

    @Override
    public Response sendRequest(Request request) {
        // 违反了里式替换原则，修改了父类的逻辑，父类并没有抛出异常
        if (StringUtils.isBlank(appId) && StringUtils.isBlank(appToken)) {
            throw new NoAuthorizationRuntimeException("...");
        }
        request.addPayload("app-id", appId);
        request.addPayload("app-token", appToken);
        return super.sendRequest(request);
    }
}
